//
//  ZSViewController.m
//  UIA段项目 墨家天气
//
//  Created by dllo on 15/8/28.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ZSViewController.h"
#import "URL.h"
@interface ZSViewController ()
@property (nonatomic,retain)UIView *headerView;
@property (nonatomic,retain)UIButton *headerBackButton;
@property (nonatomic,retain)NSMutableDictionary *dic;
@property (nonatomic,retain)UIImageView *backGroundView;
@property (nonatomic,retain)UIView *blackView;
@end

@implementation ZSViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.dic = [NSMutableDictionary dictionary];
        
        
    }
    return self;
    
}
-(void)dealloc
{
    
    [_cityName release];
    [_zhishutype release];
    [_headerView release];
    [_dic release];
    [_backGroundView release];
    [_blackView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self addHandle];
    [self addBackGroundView];
    [self addHeaderView];
}

- (void)addHandle
{

    NSString *stringCity = [self.cityName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];
 
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  
    [dic setObject:@"2" forKey:@"cAct"];
    [dic setObject:@"211" forKey:@"act"];
    [dic setObject:@"1010702012102000002" forKey:@"city"];
    [dic setObject:stringCity forKey:@"cityName"];
    [dic setObject:self.zhishutype forKey:@"id"];
    [dic setObject:@"4" forKey:@"mt"];
    [dic setObject:@"3.11.1" forKey:@"sv"];
    [dic setObject:@"4.4.4" forKey:@"osv"];
    [dic setObject:@"868033019886185" forKey:@"imei"];
    [dic setObject:@"M040" forKey:@"dm"];
    [dic setObject:@"10" forKey:@"nt"];
    [dic setObject:@"401FFD8CECB45C1FB7D40679012FC227%7C581688910330868" forKey:@"CUID"];
    [dic setObject:@"115" forKey:@"pid"];
    [dic setObject:@"1009967d" forKey:@"chl"];
    
    
    [URL conectionWithUrl:@"http://tq.91.com/api" dic:dic block:^(NSData *data) {
        self.dic = [NSJSONSerialization JSONObjectWithData:data options:NSUTF8StringEncoding error:nil];
   

        [self addView];
        
    }];
    
    
    
    
}
- (void)addHeaderView
{
    
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60 * OffHeight)];
    _headerView.backgroundColor = [UIColor blackColor];
    _headerView.alpha = 0.5;
    [self.view addSubview:_headerView];
    [_headerView release];
    
    
    
    self.headerBackButton = [[UIButton alloc]init];
    _headerBackButton.frame = CGRectMake(10 * OffWidth, 25 * OffHeight, 50 * OffWidth, 30 * OffHeight);
    _headerBackButton.highlighted = YES;
    [_headerBackButton setTitle:@"back" forState:UIControlStateNormal];
    [_headerBackButton addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_headerBackButton];
    [_headerBackButton release];
    
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 30 * OffWidth, 30 * OffHeight, 60 * OffWidth, 30 * OffHeight)];
    title.text = self.cityName;
    title.font = [UIFont boldSystemFontOfSize:20 * OffWidth];
    title.textColor = [UIColor whiteColor];
    [self.view addSubview:title];
    [title release];
    
}


- (void)addBackGroundView

{
    self.backGroundView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _backGroundView.image = [UIImage imageNamed:@"da.jpg"];
   [self.view addSubview:_backGroundView];
    [_backGroundView release];

    
    
    UIBlurEffect *ef = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effV = [[UIVisualEffectView alloc]initWithEffect:ef];
    effV.frame = [UIScreen mainScreen].bounds;
    [_backGroundView addSubview:effV];
    [_backGroundView release];
    
 

}
- (void)addView
{
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 130 * OffHeight, self.view.frame.size.width, self.view.frame.size.height )];
    [_backGroundView addSubview:view];
    [view release];
    
    
    
    
    UILabel *location = [[UILabel alloc]initWithFrame:CGRectMake(0, 150 * OffHeight, 30 * OffWidth, 30 * OffHeight)];
    location.text = [self.dic objectForKey:self.cityName];
    [_backGroundView addSubview:location];
    [location release];
    
    UILabel *weather = [[UILabel alloc]initWithFrame:CGRectMake(10 * OffWidth, 40 * OffHeight, 150 * OffWidth,  100 * OffHeight)];
    weather.text = [[self.dic objectForKey:@"weather"]objectForKey:@"climatic"];
    weather.textColor = [UIColor whiteColor];
    weather.layer.masksToBounds = YES;
    weather.textAlignment = 0;
    weather.font = [UIFont boldSystemFontOfSize:40 * OffWidth];
    [self.backGroundView addSubview:weather];
    [weather release];
    
    
    UILabel *temp = [[UILabel alloc]initWithFrame:CGRectMake(400 * OffWidth, 150 * OffHeight, 80 * OffWidth, 30 * OffHeight)];
    temp.text = [self.dic objectForKey:@"temp"];
    temp.textColor = [UIColor whiteColor];
    [_backGroundView addSubview:temp];
    [temp release];
    
    
    UILabel *text = [[UILabel alloc]initWithFrame:CGRectMake(20 * OffWidth, 300 * OffHeight, 200 * OffWidth, 30 * OffHeight)];
    text.text = [self.dic objectForKey:@"text"];
    text.font = [UIFont boldSystemFontOfSize:20 * OffWidth];
    text.textColor = [UIColor whiteColor];
    [_backGroundView addSubview:text];
    [text release];
    
    
    UILabel *info = [[UILabel alloc]initWithFrame:CGRectMake(20 * OffWidth, 330 * OffHeight, self.view.frame.size.width, 30 * OffHeight)];
    info.font = [UIFont boldSystemFontOfSize:23 * OffWidth];
    info.text = [self.dic objectForKey:@"info"];
    info.textColor = [UIColor whiteColor];
    [_backGroundView addSubview:info];
    [info release];
    
    UILabel *publish = [[UILabel alloc]initWithFrame:CGRectMake(20 * OffWidth, self.view.frame.size.height - 150 * OffHeight, 200 * OffWidth, 30 *OffHeight)];
    publish.text = [self.dic objectForKey:@"publish"];
    [_backGroundView addSubview:publish];
    [publish release];

 
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [self addView];
    
}



- (void)backClick:(UIButton *)button
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}



@end
